GBML manual / Strings

string_to_number

s read as a number - converting text to a number, e.g. reading back a value someone typed on a name/number entry screen.

Syntax

string_to_number(s) -> real

Arguments

NameType
sstring

Returns

real

Description

s read as a number - converting text to a number, e.g. reading back a value someone typed on a name/number entry screen.

Reads an optional leading -/+, digits, and an optional decimal point and more digits, stopping at the first character that is not part of a number - "12abc" reads as 12. Text with no digits anywhere (empty, or not numeric at all) reads as 0, the one documented default.

Example

var typed = "42";
var value = string_to_number(typed);
var positive = value > 0;

Use int_round/int_floor/int_part (Maths) on the result if you want a whole int rather than a real.

On the GBA

Reads an optional leading -/+, digits, and an optional decimal point and more digits, stopping at the first character that is not part of a number - "12abc" reads as 12. Text with no digits anywhere (empty, or not numeric at all) reads as 0, the one documented default. Use int_round/int_floor/int_part (Maths) on the result if you want a whole int rather than a real.

See also: string